<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Products extends CI_Controller{
	
	public function index(){
		
		//TODO möjligvis ta bort denna då listing ersatte den när vi körde med kategorier
		
		$data['title'] = "Produkter";
		
		//Hämtar alla producter mha modellen
		$data['products'] = $this->cart_model->retrieve_products();
		
		//skickar cart/products till index sidan som sedan echoas ut och innehållet från products.php i views/cart visas
		$data['content'] = 'cart/products'; 
		
		// Laddar carten även vid post
		//$data['cartPostContent'] = 'cart/cart';

		//Laddar sidan/viewn
    	$this->load->view('index', $data);
		
    	
    	//print_r($data['products']);

	}

	function show_detailed_product(){
		
		$result = $this->product_model->get_product();
		if($result != false){
			$data['title'] = $result->name;	
			$data['singleProduct'] = $result;
			$data['content'] = 'products/productDetailed'; 
			//$data['cartPostContent'] = 'cart/cart';

			//Laddar index/masterpage
	    	$this->load->view('index', $data);
		}
	}
	
	function listing()
	{
		$data['products'] = $this->product_model->retrive_products_by_id();
		$data['title'] = "Produkter";
		
		if($data['products'] != null)
		{
			$row = $this->product_model->retrive_category();
			$data['title'] = $row->categoryName;
		}
		
		$data['content'] = 'cart/products';
		//$data['cartPostContent'] = 'cart/cart';
		$this->load->view('index', $data);
	}
	
	function categories()
	{
		$result = $this->product_model->list_categories();
		$data['title'] = "Kategorier";
		//$data['cartPostContent'] = 'cart/cart';
		$data['content'] = 'products/categories';
		$data['categories'] = $result;
		
		$this->load->view('index', $data);
	}
}